package can;

import static org.junit.Assert.assertEquals;

import robocode.control.testing.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that ConnellBot always
 * beats Corners.
 * 
 * @author Andrea
 */
public class TestConnellBotVersusCorners extends RobotTestBed {

  /**
   * Specifies that Corners and ConnellBot are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Corners,can.ConnellBot";
  }
  
  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * The actual test, which asserts that ConnellBot has won every round against Corners.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] results = event.getIndexedResults();
    System.out.println("I won " + results[1].getFirsts() + " rounds out of " + getNumRounds());

    // Check to make sure ConnellBot won every round.
    assertEquals("Check ConnellBot winner", results[1].getFirsts(), getNumRounds());
  }

}
